package com.mininglamp.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.mininglamp.crud.GoodsCrud;
import com.mininglamp.mapper.GoodsMapper;
import com.mininglamp.model.Goods;
import com.mininglamp.utils.Pager;

@Service
public class GoodsService {
	
	
	@Autowired
	GoodsCrud goodsCrud;
	
	@Autowired
	GoodsMapper goodsMapper;
	/**
	 * 插入商品
	 * @param goods
	 * @return
	 */
	public int inserGoods(Goods goods){
		int flag = 0;
		if(goods!=null){
			
			goodsCrud.save(goods);
			flag = 1;
		}else{
			flag = 0;
		}
		return flag;
	}
	/**
	 * 查询分页商品信息
	 * @param pager
	 * @param wetchatsId
	 * @return
	 */
	public Pager searchGoodsPage(Pager pager,String wetchatsId){
		PageBounds pageBounds = new PageBounds(pager.getPageNum(),pager.getPageSize());
		
		PageList<Goods> list = goodsMapper.searchGoodsPage(pageBounds, wetchatsId);
		
		pager.setDatas(list);
		pager.setTotalNum(list.getPaginator().getTotalCount());
		return pager;
	}

}
